<template>
    <div class="top-header">
        <div class="top-img"></div>
    </div>	
    <h1>{{ $t('Please_wait') }} ...</h1>
</template>

<script setup>
	import axios from '@/utils/api'
	import {useRoute,useRouter} from 'vue-router'
    import { useUserInfoStore } from '@/store/modules/user_info/index';
    import {reactive,ref } from 'vue'
    import { useLoadingStore } from '@/store/modules/loading/index';
    const loadingStore = useLoadingStore();
    const user_infoStore = useUserInfoStore();
    const user_info = reactive(user_infoStore.userInfo)
	const route = useRoute()
	const router = useRouter()

    const lang = ref('')
	if(localStorage.getItem('lang') == 'en'){
		lang.value = 'en'
	}else{
		lang.value = 'zh'
	}
	const yh_bind =async ()=>{
            const res = await axios.get(`/yh_binding?code=${route.query.code}&state=${route.query.state}`)
            console.log(res);

            if(res.code == 200){
                if(lang.value == 'en'){
                    ElMessage.success('Binding successful')
                }else{
                    ElMessage.success('綁定成功')
                }

                // const data = {
                //     user_id:route.query.state,
                // }
                // const list = await axios.post('/getUserInfo',data)
                // user_infoStore.setUserinfo(list.data.user_info)
                
            }else if(res.code == 60001){
                if(lang.value == 'en'){
                    ElMessage.error('The Yahoo account has already been linked')
                }else{
                    ElMessage.error('該yahoo帳號已經綁定')
                }

                setTimeout(()=>{
                    loadingStore.stopLoading();
                    if(window.innerWidth < 1024 && window.baseUrl == "http://192.168.110.244:8081/game/public"){
                        window.location.href = 'http://localhost:5178/#/pages/My/index';
                        console.log('跳转本地移动端链接');
                    }
                    if(window.innerWidth < 1024 && window.baseUrl !== "http://192.168.110.244:8081/game/public"){
                        window.location.href = window.hostUrl+'/pages/My/index';
                        console.log('跳转测试移动端');
                    }
                    window.location.href = '//'+window.location.hostname+'/#/userCenter'
                },1500)
                return
            }else{
                ElMessage.error(res.message)
            }
            
            setTimeout(()=>{
                if(window.innerWidth < 1024 && window.baseUrl == "http://192.168.110.244:8081/game/public"){
                    window.location.href = 'http://localhost:5178/#/pages/My/index';
                    console.log('跳转本地移动端链接');
                }
                if(window.innerWidth < 1024 && window.baseUrl !== "http://192.168.110.244:8081/game/public"){
                    window.location.href = window.hostUrl+'/pages/My/index';
                    console.log('跳转测试移动端');
                }
                window.location.href = '//'+window.location.hostname+'/#/userCenter'
                console.log(window.location.href);
                
            },1500)
        
	}
    yh_bind()

    
</script>

<style lang="less" scoped>
.top-header {
    width: 100%;
    height: 110px;
    z-index: 10;
    background: linear-gradient(#2ca0d8, #2ca0d8 100%, #fff 0, #fff);
    .top-img {
        width: 100%;
        height: 110px;
        margin: 0 auto;
        background: url(https://yyfuns.com/static/logoZ.png) no-repeat;
		background-size: contain;
		background-position: center;
        transform: scale(.8);
        filter: invert(1) brightness(30);
        // background: url(https://s1.hdslb.com/bfs/static/jinkela/passport-pc/assets/rl_top.png) no-repeat;
    }
}
h1{
    text-align: center;
    margin-top: 100px;
}
</style>